// pages/my/my.js
const CONFIG = require('../../../config');
const { $await } = require('../../../utils/util'); // 格式化时间
import { shoppingAPI } from '../../../api/public/index';
Component({
  properties: {
    number: {
      type: Number,
      value: '',
    },
    channel_id: {
      type: Number,
      value: '',
    },
    shop_url:{
      type: String,
      value: '',
    }
  },
  observers: {
  },
  /**
   * 组件的初始数据
   */
  data: {
    radioInfo: {},
    page: 1,
    shopHight: '',
    tableData:[]
  },
  lifetimes: {
    created() {},
    attached() {
      this.getDate()
      this.setData({
        shopHight : wx.getStorageSync('shopH') + 30
      })
    },
  },

  pageLifetimes: {
    show: function () {
      console.log(this.data)
    },
  },

  /**
   * 组件的方法列表
   */
  methods: {
    // 获取数据
    async getDate() {
      console.log(this.data.shop_url)
      let params = {
        channel_id: this.data.channel_id,
        number: this.data.number,
        is_live: 1
      }
      const [err,res] = await $await(shoppingAPI.productLisAPI({...params}))
      if(res){
        // console.log(res);
        this.setData({
          tableData : res.list,
        })
      }
    },
    todetail: function (e) {
      const { id  } = e.currentTarget.dataset;
      console.log(id)
      let url = CONFIG.dsUrl +  '/detail/' + id + '?isToken='+ wx.getStorageSync('userInfo').ds_token + '&oId=' + wx.getStorageSync('userInfo').openid+'&from1=wxapp'
     wx.navigateTo({
       url: '/pages/webview/webview?webURL=' + encodeURIComponent(url),
     })
    },
    displayWindow(){
      let url =  CONFIG.dsUrl + '/goods_list/' + this.data.channel_id + '?isToken='+ wx.getStorageSync('userInfo').ds_token + '&oId=' + wx.getStorageSync('userInfo').openid+'&from1=wxapp'
      wx.navigateTo({
        url: '/pages/webview/webview?webURL=' + encodeURIComponent(url),
      })
    }
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    // scrolltoupper: function () {
    //   // 标题栏显示刷新图标，转圈圈
    //   wx.showNavigationBarLoading()
    //   // 请求最新数据
    //   this.setData({
    //     page: 1,
    //     tableData:[]
    //   })
    //   this.getDate();
    //   setTimeout(() => {
    //     // 标题栏隐藏刷新转圈圈图标
    //     wx.hideNavigationBarLoading()
    //   }, 1000);
    // },
    // /**
    //  * 页面上拉触底事件的处理函数
    //  */
    // scrolltolower: function () {
    //   setTimeout(() => {
    //     this.getDate();
    //   }, 300);
    // },
  },

})